package com.solution.webutil;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts.tiles.TilesRequestProcessor;

import com.solution.constant.LoginConstants;


/**
 *
 *
 */

public class CustomRequestProcessor extends TilesRequestProcessor {
	protected boolean processPreprocess(HttpServletRequest request,
			HttpServletResponse response) {
		HttpSession session = request.getSession(false);
		//If user is trying to access login page
		// then don't check 
		if (request.getServletPath().equals("/logout.do"))
			return true;
		if (request.getServletPath().equals("/examineeLogout.do"))
			return true;
		if (request.getServletPath().equals("/loginFront.do"))
			return true;
		if (request.getServletPath().equals("/resetPassword.do"))
			return true;
		if (request.getServletPath().equals("/resetPasswordSubmit.do"))
			return true;
		//Check if userName attribute is there is session.
		//If so, it means user has already logged in
		if (session != null && session.getAttribute(LoginConstants.SESSION_USER_INFO) != null)
			return true;
		else {
			try {
				//If no redirect user to login Page
				request.getRequestDispatcher("/logout.do").forward(request,
						response);
			} catch (Exception ex) {
			}
		}
		return false;
	}
}

